<!--出库明细-->
<template>
  <el-card
    shadow="never"
    body-style="padding: 0px 0px 20px 0px;background:#FAFAFA"
    style="margin-top: 10px">
   
      <el-row>
        <el-col :span="24">
          <!--数据列表-->
          <el-table
            :data="tableData"
            header-cell-class-name="table-header"
            style="width: 100%;margin-top: 20px"
            show-overflow-tooltip>
            <el-table-column
              label="序号"
              type="index"
              width="45">
            </el-table-column>
            <el-table-column
              prop="fishSpecies"
              label="产品种类">
            </el-table-column>
            <el-table-column
              prop="outNum"
              label="出库数量(kg)"
            >
            </el-table-column>
            <el-table-column
              prop="productionDate"
              label="生产日期">
            </el-table-column>
            <el-table-column
              prop="outTime"
              label="出库录入时间"
              >
            </el-table-column>
            <el-table-column
              prop="outName"
              label="出库操作人"
              >
            </el-table-column>
          </el-table>


        </el-col>
      </el-row>
  </el-card>
</template>

<script>
import { queryEquipmentDetailById, getActualStock } from '@/api/warehouse'

export default {
  name: 'EquipmentEx',
  props: {
    // 0为出库单管理只读；1出库管理可编辑状态
    type: {
      type: Number,
      default: 0
    },
    warehouseId: {
      type: String,
      default: ''
    },
    form: {
      type: Object,
      default: function() {
        return {
          id: '',
          equipmentTypeId: [],
          outNum: 0,
          outStockNum: 0,
          labelWay: '',
          shelfLife: ''
        }
      }
    },
    treeData: {
      type: Array,
      default: function() {
        return []
      }
    },
    tableData: {
      type: Array,
      default: function() {
        return []
      }
    }
    // tableData: {
    //   type: Object,
    //   default: function() {
    //     return {
    //       id: '',
    //       expirationDate: '',
    //       fishSpecies: '',
    //       fishpondName: '',
    //       inName: '',
    //       inTime: '',
    //       outName: '',
    //       outNum: '',
    //       outTime: '',
    //       productionDate: ''
    //     }
    //   }
    // }
  },
  data() {
    return {
      modelLoading: false,
      treeProps: { value: 'id', label: 'name' },
      equipmentData: {
        type: Object,
        default: function() {
          return {
            id: '',
            name: '',
            model: '',
            modelName: '',
            parentId: '',
            category: '',
            labelType: '',
            labelTypeName: '',
            installMethod: '',
            installMethodName: '',
            labelSize: '',
            labelSizeName: '',
            labelWay: '',
            labelWayName: '',
            equipmentGuide: '',
            equipmentImg: '',
            labelInstallImg: ''
          }
        }
      }
    }
  },
  mounted() {
    const data = {}
    Object.assign(data, this.equipmentDataExtra)
    this.equipmentData = data
  },
  methods: {
    isReadOnly() {
      return this.type == 0 || this.type == 2
    },
    handleDelete() {
      this.$confirm('确认删除此器材?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消'
      }).then(() => {
        this.$emit('onDelete', {})
      })
    },
    treeChange(item) {
      const id = item[item.length - 1]
      this.$parent.handleSelectEquipmentList()
      const a = new Promise(resolve => {
        getActualStock({ equipmentTypeId: id, warehouseId: this.warehouseId }).then(res => {
          resolve(res.resultData)
        })
      })

      const b = new Promise(resolve => {
        queryEquipmentDetailById({ equipmentTypeId: id }).then(res => {
          resolve(res.resultData)
        })
      })

      Promise.all([a, b]).then(res => {
        const data = res[1]
        this.equipmentData = {
          name: data.name,
          model: data.model,
          modelName: data.modelName,
          equipmentTypeId: data.equipmentTypeId,
          parentId: data.parentId,
          category: data.category,
          labelType: data.labelType,
          labelTypeName: data.labelTypeName,
          installMethod: data.installMethod,
          installMethodName: data.installMethodName,
          labelSize: data.labelSize,
          labelSizeName: data.labelSizeName,
          labelWay: data.labelWay,
          labelWayName: data.labelWayName,
          equipmentGuide: data.equipmentGuide,
          equipmentImg: data.equipmentImg,
          labelInstallImg: data.labelInstallImg
        }
        this.form.labelWay = data.labelWay
        this.form.outNum = 0
        this.form.outStockNum = res[0]
      })
    },
    async validData() {
      const _this = this
      return new Promise(function(resolve, reject) {
        _this.$refs['form'].validate((valid) => {
          if (valid) {
            resolve()
            return true
          } else {
            reject()
            return false
          }
        })
      })
    },
    /**
     * 选择型号
     * @param item
     */
    handleSelectModel(item) {
      // console.log(item)
    }
  }
}
</script>

<style lang="scss" scoped>

</style>
